/* GUI CONVERTED from sqqomtp.p (converter v1.76) Tue Aug 20 15:42:05 2002 */
/* sqqomtp.p - QUOTE MAINTENANCE - HEADER FRAME B UPDATE                      */
/* Copyright 1986-2002 QAD Inc., Carpinteria, CA, USA.                        */
/* All rights reserved worldwide.  This is an unpublished work.               */
/* $Revision: 1.38 $                                                          */
/*V8:ConvertMode=Maintenance                                                  */
/* REVISION: 7.3      LAST MODIFIED: 09/18/92   BY: tjs *G035*                */
/* REVISION: 7.3      LAST MODIFIED: 01/11/93   BY: mpp *G485*                */
/* REVISION: 7.3      LAST MODIFIED: 02/02/93   BY: bcm *G414*                */
/* REVISION: 7.3      LAST MODIFIED: 02/02/93   BY: mpp *G626*                */
/* REVISION: 7.3      LAST MODIFIED: 02/17/93   BY: bcm *G691*                */
/* REVISION: 7.3      LAST MODIFIED: 06/01/93   BY: afs *GB31*                */
/* REVISION: 7.3      LAST MODIFIED: 06/10/93   BY: wep *H005*                */
/* REVISION: 7.4      LAST MODIFIED: 08/23/93   BY: cdt *H049*                */
/* REVISION: 7.4      LAST MODIFIED: 09/28/93   BY: cdt *H086*                */
/* REVISION: 7.4      LAST MODIFIED: 10/19/93   BY: cdt *H184*                */
/* REVISION: 7.4      LAST MODIFIED: 05/11/94   BY: dpm *H368*                */
/* REVISION: 7.4      LAST MODIFIED: 06/29/94   BY: qzl *H418*                */
/* REVISION: 7.4      LAST MODIFIED: 06/29/94   BY: qzl *H419*                */
/* REVISION: 7.4      LAST MODIFIED: 07/05/94   BY: tjs *FN95*                */
/* REVISION: 7.3      LAST MODIFIED: 06/22/94   BY: WUG *GK60*                */
/* REVISION: 7.4      LAST MODIFIED: 07/08/94   BY: bcm *H437*                */
/* REVISION: 7.4      LAST MODIFIED: 07/29/94   BY: bcm *H465*                */
/* REVISION: 7.4      LAST MODIFIED: 08/28/94   BY: srk *GL70*                */
/* Oracle changes (share-locks)      09/13/94   BY: rwl *GM51*                */
/* REVISION: 7.2      LAST MODIFIED: 09/15/94   BY: dpm *FR43*                */
/* REVISION: 7.4      LAST MODIFIED: 09/29/94   BY: bcm *H541*                */
/* REVISION: 8.5      LAST MODIFIED: 10/18/94   BY: mwd *J034*                */
/* REVISION: 8.5      LAST MODIFIED: 10/19/94   BY: ljm *GN40*                */
/* REVISION: 8.5      LAST MODIFIED: 11/08/94   BY: ljm *GO33*                */
/* REVISION: 8.5      LAST MODIFIED: 04/10/95   BY: yep *G0KL*                */
/* REVISION: 8.5      LAST MODIFIED: 03/22/95   BY: jlf *J042*                */
/* REVISION: 8.5      LAST MODIFIED: 03/29/95   BY: dzn *F0PN*                */
/* REVISION: 8.5      LAST MODIFIED: 09/13/95   BY: ais *H0FW*                */
/* REVISION: 8.5      LAST MODIFIED: 07/06/95   BY: taf *J053*                */
/* REVISION: 8.5      LAST MODIFIED: 04/02/96   BY: mzh *J0FQ*                */
/* REVISION: 8.5      LAST MODIFIED: 04/11/96   BY: ais *G1GJ*                */
/* REVISION: 8.5      LAST MODIFIED: 05/13/96   BY: tzp *G1V8*                */
/* REVISION: 8.5      LAST MODIFIED: 07/04/96   BY: DAH *J0XR*                */
/* REVISION: 8.5      LAST MODIFIED: 07/17/96   BY: taf *J0ZH*                */
/* REVISION: 8.5      LAST MODIFIED: 07/13/96   BY: smp *J10Z*                */
/* REVISION: 8.5      LAST MODIFIED: 09/16/96   BY: *G2F0* Ajit Deodhar       */
/* REVISION: 8.5      LAST MODIFIED: 10/17/96   BY: *G2H5* Ajit Deodhar       */
/* REVISION: 8.6      LAST MODIFIED: 10/21/97   BY: *J23V* Nirav Parikh       */
/* REVISION: 8.6      LAST MODIFIED: 11/18/97   BY: *J25B* Aruna Patil        */
/* REVISION: 8.6      LAST MODIFIED: 11/25/97   BY: *H1GW* Niranjan Ranka     */
/* REVISION: 8:6      LAST MODIFIED: 12/09/97   BY: *K1BP* Val Portugal       */
/* REVISION: 8.6      LAST MODIFIED: 01/29/98   BY: *J2BC* Aruna Patil        */
/* REVISION: 8.6E     LAST MODIFIED: 02/23/98   BY: *L007* Annasaheb Rahane   */
/* REVISION: 8.6E     LAST MODIFIED: 05/11/98   BY: *J2L3* Niranjan Ranka     */
/* REVISION: 8.6E     LAST MODIFIED: 06/11/98   BY: *L01S* Russ Witt          */
/* REVISION: 8.6E     LAST MODIFIED: 09/08/98   BY: *L08W* Russ Witt          */
/* REVISION: 9.0      LAST MODIFIED: 11/24/98   BY: *M017* David Morris       */
/* REVISION: 9.0      LAST MODIFIED: 02/17/99   BY: *M08C* Hemali Desai       */
/* REVISION: 9.0      LAST MODIFIED: 03/13/99   BY: *M0BD* Alfred Tan         */
/* REVISION: 9.1      LAST MODIFIED: 03/24/00   BY: *N08T* Annasaheb Rahane   */
/* REVISION: 9.1      LAST MODIFIED: 06/30/00   BY: *N0DX* BalbeerS Rajput    */
/* REVISION: 9.1      LAST MODIFIED: 08/12/00   BY: *N0KN* Mark Brown         */
/* REVISION: 9.1      LAST MODIFIED: 09/25/00   BY: *N0WC* Mudit Mehta        */
/* Revision: 1.27          BY: Katie Hilbert      DATE: 04/01/01  ECO: *P002* */
/* Revision: 1.29          BY: Sandeep Parab      DATE: 07/02/01  ECO: *M1CV* */
/* Revision: 1.31          BY: Rajiv Ramaiah      DATE: 08/31/01  ECO: *M1JT* */
/* Revision: 1.32          BY: Jean Miller        DATE: 05/08/02  ECO: *P05M* */
/* Revision: 1.33          BY: Ashish Maheshwari  DATE: 05/20/02  ECO: *P04J* */
/* Revision: 1.35          BY: Dave Caveney       DATE: 06/05/02  ECO: *P042* */
/* Revision: 1.36          BY: Robin McCarthy     DATE: 07/03/02  ECO: *P08Q* */
/* Revision: 1.37          BY: Robin McCarthy     DATE: 07/15/02  ECO: *P0BJ* */
/* $Revision: 1.38 $          BY:  Robin McCarthy      DATE: 08/15/02  ECO: *P09K* */

/******************************************************************************/
/* All patch markers and commented out code have been removed from the source */
/* code below. For all future modifications to this file, any code which is   */
/* no longer required should be deleted and no in-line patch markers should   */
/* be added.  The ECO marker should only be included in the Revision History. */
/******************************************************************************/

{mfdeclre.i}
{cxcustom.i "SQQOMTP.P"}
{gplabel.i}    /* EXTERNAL LABEL INCLUDE */
{apconsdf.i}   /* PRE-PROCESSOR CONSTANTS FOR LOGISTICS ACCOUNTING */

define new shared variable freight_ok    like mfc_logical initial yes.
define new shared variable old_ft_type   like ft_type.
define new shared variable line          like qod_line.
define new shared variable undo_sqqomtb  like mfc_logical.

define shared variable rndmthd       like rnd_rnd_mthd.
define shared variable oldcurr       like qo_curr.
define shared variable qo_recno      as   recid.
define shared variable undo_flag     like mfc_logical.
define shared variable new_order     like mfc_logical initial no.
define shared variable mult_slspsn   like mfc_logical no-undo.
define shared variable qocmmts       like qoc_hcmmts  label "Comments".
define shared variable del-yn        like mfc_logical.
define shared variable calc_fr       like mfc_logical label "Calculate Freight".
define shared variable disp_fr       like mfc_logical label "Display Weights".
define shared variable promise_date  as  date         label "Promise Date".
define shared variable rsn_lost      like qod_rsn_lost.
define shared variable qocrt_int     like qod_crt_int.
define shared variable line_pricing  like pic_qo_linpri.
define shared variable reprice       like mfc_logical.
define shared variable picust        like cm_addr.
define shared variable cfexists      like mfc_logical.
define shared variable cf_chr        as character.
define shared variable cf_cfg_path   like mfc_char.

define variable old_fr_terms     like qo_fr_terms.
define variable old_um           like fr_um.
define variable tax_nbr          like tx2d_nbr initial "".
define variable tax_tr_type      like tx2d_tr_type initial "10".
define variable qoc_pt_req       like mfc_logical.
define variable old_slspsn       as   character format "x(8)" no-undo.
define variable old_comm_pct     as   decimal format ">>9.99" no-undo.
define variable l_up_comm        like mfc_logical   no-undo.
define variable l_qo_fix_pr      like mfc_logical   no-undo.
define variable mc-error-number  like msg_nbr       no-undo.
define variable o-error_flag     like mfc_logical   no-undo.
define variable l_old_pricing_dt like qo_pricing_dt no-undo.
define variable use-log-acctg    as logical         no-undo.

define shared frame a.
/*V8+*/
define shared frame b.
define shared frame b1.

{pppivar.i "new"}  /*Shared pricing variables*/

{gptxcdec.i}  /* Define shared variables for gptxcval.i. */

define workfile cf_qod_rm
   field cf_ccq_name as character.

{sqqomt02.i}  /* Form definitions for shared frames a and b */

/*V8+*/

find qo_mstr where recid(qo_mstr) = qo_recno.
find first gl_ctrl no-lock.
find first qoc_ctrl no-lock.

/* CHECK IF LOGISTICS ACCOUNTING IS ENABLED */
{gprun.i ""lactrl.p"" "(output use-log-acctg)"}
/*GUI*/ if global-beam-me-up then undo, leave.


reprice = no.

display
   reprice
with frame b.

l_old_pricing_dt = qo_pricing_dt.

order-header:
do on error undo, retry with frame b:
/*GUI*/ if global-beam-me-up then undo, leave.


   set
      qo_ord_date
      qo_exp_date
      qo_confirm
      qo_flw_date
      qo_pricing_dt
      qo_po
      qo_rmks
      reprice      when (not new_order)
      line_pricing when (new_order)
      qo_pr_list
/*cli      qo_site */
      qo_channel
      qo_project
      qo_release
      qo_curr      when (new qo_mstr)
      qo_lang
      qo_taxable
      qo_taxc
      qo_tax_date
      l_qo_fix_pr
      qo_cr_terms
      qocrt_int
      qo_cycle
      qo_recur
   go-on ("F5" "CTRL-D")
   editing:

      /* DISPLAY INTEREST AFTER ENTERING CREDIT TERMS */
      readkey.

      if frame-field = "qo_pricing_dt"
      then do:

         if (keyfunction(lastkey) = "TAB"
         or  keyfunction(lastkey) = "GO"
         or  keyfunction(lastkey) = "CURSOR-DOWN"
         or  keyfunction(lastkey) = "CURSOR-UP"
         or  keyfunction(lastkey) = "RETURN")
         then do:

            if  not new qo_mstr
            and input qo_pricing_dt <> l_old_pricing_dt
            and (can-find(mfc_ctrl
                          where mfc_field   = "qoc_pc_line"
                          and   mfc_logical = no))
            then do:

               reprice = yes.

               display
                  reprice
               with frame b.

            end. /* IF NOT NEW qo_mstr ... */
         end. /* IF (KEYFUNCTION(LASTKEY) = "TAB" ... */
      end. /* IF FRAME-FIELD = "qo_pricing_dt" */

      if frame-field = "qo_cr_terms" then do:
         if (lastkey = keycode("RETURN") or
            lastkey = keycode("CTRL-X") or
            lastkey = keycode("F1"))
         then do:
            find first ct_mstr where ct_code = input qo_cr_terms
               no-lock no-error.
            if available ct_mstr then do:
               display
                  string(ct_terms_int,"->>>9.99") @ qocrt_int.
               qocrt_int = ct_terms_int.
            end. /* IF AVAILABLE CT_MSTR */
         end. /* LASTKEY = RETURN, F1 OR CTRL-X */
      end. /* FRAME-FIELD = QO_CR_TERMS */

      apply lastkey.

   end. /* EDITING */

   /* UPDATE THE LINE ITEM PRICING DATE WITH THE HEADER PRICING DATE. */

   if  not new qo_mstr
   and (qo_pricing_dt <> l_old_pricing_dt
   and (can-find(mfc_ctrl
                 where mfc_field   = "qoc_pc_line"
                 and   mfc_logical = no)))
   then do:

      reprice = yes.
      display
         reprice
      with frame b.

      for each qod_det where qod_nbr = qo_nbr
      exclusive-lock:
         qod_pricing_dt = qo_pricing_dt.
      end. /* FOR EACH qod_det */

   end. /* IF NOT NEW qo_mstr ... */

   assign
      qo_mstr.qo__qad03 = integer(l_qo_fix_pr) + 1 .

   /* IF CUSTOMER REQUIRES A PO NUMBER, ENSURE ONE IS SPECIFIED IF
      USER IS TRYING TO SET UP QUOTE TO BE RELEASED    */
   if qo_release and qo_po = "" then do:
      find cm_mstr where cm_addr = qo_cust no-lock.
      if cm_po_reqd then do:
         {pxmsg.i &MSGNUM=631 &ERRORLEVEL=3}
         /* PURCHASE ORDER IS REQUIRED FOR THIS CUSTOMER */
         next-prompt qo_po with frame b.
         undo, retry.
      end.
   end.

   if input qo_cr_terms <> ""
   then do:
      find first ct_mstr where ct_code = input qo_cr_terms
      no-lock no-error.
      if not available ct_mstr then do:
         /* CREDIT TERM CODE MUST EXIST OR BE BLANK */
         {pxmsg.i &MSGNUM=840 &ERRORLEVEL=3}
         next-prompt qo_cr_terms with frame b.
         undo order-header, retry order-header.
      end.
   end.

   qo_recno = recid(qo_mstr).

   /* VALIDATE LINE PRICING OPTION VALID */
   if new_order and not line_pricing then do:

      find first mfc_ctrl where mfc_field = "qoc_pt_req"
      no-lock no-error.

      if available mfc_ctrl and mfc_logical then do:
         /* PRICE LIST REQUIRED AND NO LINE PRICING NOT ALLOWED */
         {pxmsg.i &MSGNUM=1277 &ERRORLEVEL=3}
         next-prompt line_pricing.
         undo order-header, retry order-header.
      end.

   end. /* IF NOT LINE_PRICING */

   /* DELETE */
   if lastkey = keycode("F5") or lastkey = keycode("CTRL-D")
   then do:
      del-yn = yes.
      {pxmsg.i &MSGNUM=11 &ERRORLEVEL=1 &CONFIRM=del-yn}
      if not del-yn then undo, retry.
   end.

   if del-yn then do:

      line = 0.

      for each qod_det exclusive-lock where qod_nbr = qo_nbr:
/*GUI*/ if global-beam-me-up then undo, leave.


         {gprun.i ""gpsiver.p""
            "(input qod_site, input ?, output return_int)"}
/*GUI*/ if global-beam-me-up then undo, leave.

         if return_int = 0 then do:
            /* DELETE NOT ALLOWED; USER DOES NOT */
            /* HAVE ACCESS TO DETAIL SITE(S)     */
            {pxmsg.i &MSGNUM=2709 &ERRORLEVEL=4}
            undo order-header, retry.
         end.

         line = line + 1.

         /* DELETE LINE ITEM COMMENTS */
         for each cmt_det exclusive-lock where cmt_indx = qod_cmtindx:
            delete cmt_det.
         end.

         /* DELETE QUOTE BILL DETAIL*/
         for each sob_det exclusive-lock
            where sob_nbr = "qod_det" + qod_nbr
              and sob_line = qod_line:
            for each cmt_det exclusive-lock where cmt_indx = sob_cmtindx:
               delete cmt_det.
            end.

            delete sob_det.
         end.

         if cfexists and qod__qad01[1] <> "" then do:
            create cf_qod_rm.
            assign cf_ccq_name = qod__qad01[1].
         end.

         {gprun.i ""sqqoapm4.p"" "(input qod_nbr, input qod_line)"}
/*GUI*/ if global-beam-me-up then undo, leave.

         delete qod_det.

      end.
/*GUI*/ if global-beam-me-up then undo, leave.
  /* Line item delete */

      /* Line item record(s) deleted. */
      {pxmsg.i &MSGNUM=24 &ERRORLEVEL=1 &MSGARG1=line}
      hide message.

      {gprun.i ""txdelete.p"" "(input tax_tr_type,
                                input qo_nbr,
                                input tax_nbr)"}
/*GUI*/ if global-beam-me-up then undo, leave.


      /* DELETE HEADER COMMENTS */
      for each cmt_det exclusive-lock where cmt_indx = qo_cmtindx:
         delete cmt_det.
      end.

      /* DELETE ANY AD_MSTR CREATED WITH TEMP SO_SHIP */
      if qo_ship = "qadtemp" + mfguser
      then do:
         find ad_mstr where ad_addr = qo_ship exclusive-lock.
         delete ad_mstr.
      end.

      /* DELETE PRICE LIST HISTORY */
      {gprun.i ""gppihdel.p"" "( 2, qo_nbr, 0 )"}
/*GUI*/ if global-beam-me-up then undo, leave.


      {&SQQOMTP-P-TAG1}
      /* DELETE EXCHANGE RATE USAGE RECORDS */
      {gprunp.i "mcpl" "p" "mc-delete-ex-rate-usage"
         "(input qo_exru_seq)"}

      {gprun.i ""sqqoapm3.p"" "(input qo_nbr)"}
/*GUI*/ if global-beam-me-up then undo, leave.


      /* IF LOGISTICS ACCOUNTING IS ENABLED DELETE lacd_det                   */
      if use-log-acctg then do:

         {gprunmo.i &module = "LA" &program = "laosupp.p"
                    &param  = """(input 'DELETE',
                                  input '{&TYPE_Quote}',
                                  input qo_nbr,
                                  input ' ',
                                  input ' ',
                                  input ' ',
                                  input no,
                                  input no)"""}
      end.   /* use-log-acctg */

      delete qo_mstr.

      if cfexists then do:
         for each cf_qod_rm:
            os-delete value(cf_cfg_path + cf_chr + cf_ccq_name).
         end.
      end.

      clear frame a.
/*GUI*/ RECT-FRAME-LABEL:SCREEN-VALUE in frame a = F-a-title.

      /*V8+*/
      clear frame b.
/*GUI*/ RECT-FRAME-LABEL:SCREEN-VALUE in frame b = F-b-title.
      del-yn = no.
      leave order-header.

   end. /* Delete */

   /* VALIDATE CURRENCY AND GET DEFAULT EXCHANGE RATE */
   if new qo_mstr then do:

      if base_curr <> qo_curr then do:
         /* VALIDATE CURRENCY ENTERED */
         {gprunp.i "mcpl" "p" "mc-chk-valid-curr"
            "(input qo_curr,
              output mc-error-number)"}
         if mc-error-number <> 0 then do:
            {pxmsg.i &MSGNUM=mc-error-number &ERRORLEVEL=3}
            next-prompt qo_curr.
            undo order-header, retry.
         end.

         /* VALIDATE EXCHANGE RATE AND IF OK CREATE USAGE RECORDS */
         /* CURRENCIES AND RATES REVERSED BELOW...             */
         {gprunp.i "mcpl" "p" "mc-create-ex-rate-usage"
                 "(input qo_curr,
                   input base_curr,
                   input """",
                   input qo_ord_date,
                   output qo_ex_rate,
                   output qo_ex_rate2,
                   output qo_exru_seq,
                   output mc-error-number)"}
         if mc-error-number <> 0 then do:
            {pxmsg.i &MSGNUM=mc-error-number &ERRORLEVEL=3}
            next-prompt qo_curr.
            undo order-header, retry.
         end.

         next-prompt qo_ord_date.  /* disable previous next-prompt */

      end. /* if base_curr <> qo_curr */

   end.

   if (oldcurr <> qo_curr) or (oldcurr = "")
   then do:

      if qo_curr = gl_base_curr then
         rndmthd = gl_rnd_mthd.
      else do:
         /* GET ROUNDING METHOD FROM CURRENCY MASTER */
         {gprunp.i "mcpl" "p" "mc-get-rnd-mthd"
            "(input qo_curr,
              output rndmthd,
              output mc-error-number)"}
         if mc-error-number <> 0 then do:
            {pxmsg.i &MSGNUM=mc-error-number &ERRORLEVEL=3}
            next-prompt qo_curr.
            undo order-header, retry.
         end.
      end.
   end.

   manual_list = qo_pr_list.

   {gprun.i ""gpsiver.p""
      "(input qo_site, input ?, output return_int)"}
/*GUI*/ if global-beam-me-up then undo, leave.


   if return_int = 0 then do:
      {pxmsg.i &MSGNUM=725 &ERRORLEVEL=3}
      /* USER DOES NOT HAVE ACCESS TO THIS SITE */
      next-prompt qo_site.
      undo, retry.
   end.

   /* VALIDATE TAX CODE  */
   {gptxcval.i &code=qo_taxc &frame="b"}

   /* All validation should be above this line for frame b;     */
   /* Additional updates (in pop-up windows) below. */

   undo_sqqomtb = true.
   {&SQQOMTP-P-TAG2}
   {gprun.i ""sqqomtb.p""}
/*GUI*/ if global-beam-me-up then undo, leave.

   if undo_sqqomtb then undo order-header, retry.

   /* UPDATE ORDER HEADER TERMS INTEREST PERCENTAGE */
   if qocrt_int <> 0  and qo_cr_terms <> ""
      and (new_order or qo__qad02 <> qocrt_int)
   then do:
      find ct_mstr where ct_code = qo_cr_terms no-lock no-error.
      if available ct_mstr and qocrt_int <> 0 then do:
         if qocrt_int <> ct_terms_int then do:
            /* Entered terms interest # does not match ct interest # */
            {pxmsg.i &MSGNUM=6212 &ERRORLEVEL=2
                     &MSGARG1=qocrt_int
                     &MSGARG2=ct_terms_int}
            del-yn = yes.
            /* Do you wish to continue? */
            {pxmsg.i &MSGNUM=8500 &ERRORLEVEL=2 &CONFIRM=del-yn}
            if not del-yn then do:
               next-prompt qocrt_int.
               undo, retry.
            end.
         end.
      end.
   end.
   qo__qad02 = qocrt_int.

   /* PROMPT FOR EXCHANGE RATE INPUT NOW  */
   if qo_curr <> base_curr then do on endkey undo, retry:
      {gprunp.i "mcui" "p" "mc-ex-rate-input"
            "(input qo_curr,
              input base_curr,
              input qo_ord_date,
              input qo_exru_seq,
              input yes,
              input 15,
              input-output qo_ex_rate,
              input-output qo_ex_rate2,
              input-output qo_fix_rate)"}
   end.

   undo_flag = false.

end.
/*GUI*/ if global-beam-me-up then undo, leave.
 /*order-header*/

hide frame b no-pause.

/* Check for deleted quote and if we made it through the  */
/* first block, reset the flag to catch "F5" in the second block. */
if undo_flag then return.
else undo_flag = true.

ststatus = stline[3].
status input ststatus.
view frame b1.

promise_date = qo_due_date.
find first qod_det where qod_nbr = qo_nbr no-lock no-error.
if available qod_det and qod_per_date <> ? then
   promise_date = qod_per_date.

calc_fr = no.
disp_fr = yes.
if new_order then calc_fr = yes.

old_fr_terms = qo_fr_terms.

display
   qo_req_date
   promise_date
   qo_due_date
   qo_slspsn[1]
   mult_slspsn
   qo_comm_pct[1]
   qo_fr_list
   qo_fr_min_wt
   qo_fr_terms
   calc_fr
   disp_fr
   qo_weight_um
   qo_so_nbr
   qo_rel_cnt
   rsn_lost
   qocmmts
with frame b1.

setb1:
do on error undo, retry with frame b1:
/*GUI*/ if global-beam-me-up then undo, leave.


   assign
      old_comm_pct = qo_comm_pct[1]
      old_slspsn   = qo_slspsn[1]
      old_um = "".

   find fr_mstr where fr_list = qo_fr_list
      and fr_site = qo_site
      and fr_curr = qo_curr
   no-lock no-error.

   if not available fr_mstr then
   find fr_mstr where fr_list = qo_fr_list
      and fr_site = qo_site
      and fr_curr = base_curr
   no-lock no-error.

   if available fr_mstr then do:
      old_um = fr_um.
      if qo_weight_um = "" then
         qo_weight_um = fr_um.
   end.

   set
      qo_req_date
      promise_date
      qo_due_date
      qo_slspsn[1]
      mult_slspsn
      qo_comm_pct[1]
      qo_fr_list
      qo_fr_min_wt
      qo_fr_terms
      calc_fr
      disp_fr
      rsn_lost
      qocmmts
   go-on ("F1" "CTRL-X").

   if input qo_slspsn[1] = "" then do:
      assign qo_comm_pct[1] = 0.
      display qo_comm_pct[1] with frame b1.
      pause 0.
   end.

   /* WHEN SALESPERSON IS CHANGED PROMPT THE USER TO DEFAULT THE NEW */
   /* SALESPERSON'S COMMISSION PERCENT.                              */
   if input qo_slspsn[1] <> old_slspsn   and
      input qo_comm_pct[1] =  old_comm_pct  and
      input qo_slspsn[1]  <> ""             and
      not batchrun
   then do:
      find sp_mstr where sp_addr = input qo_slspsn[1] no-lock no-error.
      if input qo_comm_pct[1] <> sp_comm_pct then do:
         /* Salesperson changed. Update default commission? */
         {pxmsg.i &MSGNUM=1396 &ERRORLEVEL=1 &CONFIRM=l_up_comm}
         if l_up_comm then do:
            assign qo_comm_pct[1] = sp_comm_pct.
            display qo_comm_pct[1] with frame b1.
            pause 0.
         end.
      end.
   end.

   /* MUILTIPLE SLSPSN ENTRY */
   if mult_slspsn then do:
      {gprun.i ""sqqosls.p""}
/*GUI*/ if global-beam-me-up then undo, leave.

      if keyfunction(lastkey) = "end-error" then
         undo, retry.
   end.

   /* VALIDATE FREIGHT LIST */
   if qo_fr_list <> "" then do:

      find fr_mstr where fr_list = qo_fr_list
         and fr_site = qo_site
         and fr_curr = qo_curr
      no-lock no-error.

      if not available fr_mstr then
      find fr_mstr where fr_list = qo_fr_list
         and fr_site = qo_site
         and fr_curr = base_curr
      no-lock no-error.

      if not available fr_mstr then do:
         /* FREIGHT LIST # NOT FOUND FOR SITE # CURRENCY */
         {pxmsg.i &MSGNUM=670 &ERRORLEVEL=4
                  &MSGARG1=qo_fr_list
                  &MSGARG2=qo_site
                  &MSGARG3=qo_curr
                  &MSGARG4=base_curr}
         next-prompt qo_fr_list with frame b1.
         undo, retry.
      end.

   end.

   if qo_fr_list <> "" then do:

      if qo_fr_list <> "" or (qo_fr_list = "" and calc_fr) then do:

         find fr_mstr where fr_list = qo_fr_list
            and fr_site = qo_site
            and fr_curr = qo_curr
         no-lock no-error.

         if not available fr_mstr then
         find fr_mstr where fr_list = qo_fr_list
            and fr_site = qo_site
            and fr_curr = base_curr
         no-lock no-error.

         if not available fr_mstr then do:
            /* FREIGHT LIST # NOT FOUND FOR SITE # CURRENCY */
            {pxmsg.i &MSGNUM=670 &ERRORLEVEL=4
                     &MSGARG1=qo_fr_list
                     &MSGARG2=qo_site
                     &MSGARG3=qo_curr}
            undo, retry.
         end.

         if old_um <> fr_um and not new_order then do:
            /* UNIT OF MEASURE HAS CHANGED */
            {pxmsg.i &MSGNUM=675 &ERRORLEVEL=2}
            pause.
         end.
      end.

      if qo_fr_terms <> "" or
         (qo_fr_terms = "" and calc_fr)
      then do:
         find ft_mstr where ft_terms = qo_fr_terms no-lock no-error.
         if not available ft_mstr then do:
            /* Invalid Freight Terms */
            {pxmsg.i &MSGNUM=671 &ERRORLEVEL=3 &MSGARG1=qo_fr_terms}
            next-prompt qo_fr_terms with frame b1.
            undo setb1, retry.
         end.
      end.

      if qo_fr_terms <> old_fr_terms and
         not new_order and not calc_fr
      then do:
         /* CALCULATION REQUIRED WHEN FREIGHT TERMS CHANGE */
         {pxmsg.i &MSGNUM=681 &ERRORLEVEL=4}
         next-prompt calc_fr with frame b1.
         undo setb1, retry.
      end.

   end.  /* Freight Parameters */

   /* VALIDATION FOR FREIGHT TERMS WITH BLANK FREIGHT LIST      */

   /* VALIDATE qo_fr_terms WHEN ENTERED */
   if qo_fr_terms <> "" then do:
      find ft_mstr where ft_terms = qo_fr_terms no-lock no-error.
      if not available ft_mstr then do:
         /* INVALID FREIGHT TERMS */
         {pxmsg.i &MSGNUM=671 &ERRORLEVEL=3 &MSGARG1=qo_fr_terms}
         next-prompt qo_fr_terms with frame b1.
         undo setb1, retry.
      end. /* END OF NOT AVAILABLE ft_mstr */
   end. /* END OF qo_fr_terms <> "" */

   if use-log-acctg and qo_fr_terms <> old_fr_terms and not new_order then do:
      if qo_fr_terms = "" then do:
         /* DELETE LOGISTICS ACCTG CHARGE DETAIL */
         {gprunmo.i  &module = "LA" &program = "laosupp.p"
                     &param  = """(input 'DELETE',
                                   input '{&TYPE_Quote}',
                                   input qo_nbr,
                                   input ' ',
                                   input ' ',
                                   input ' ',
                                   input no,
                                   input no)"""}
      end.
      else do:
         /* UPDATE LOGISTICS ACCTG CHARGE DETAIL */
         {gprunmo.i  &module = "LA" &program = "laosupp.p"
                     &param  = """(input 'MODIFY',
                                   input '{&TYPE_Quote}',
                                   input qo_nbr,
                                   input ' ',
                                   input ft_lc_charge,
                                   input ft_accrual_level,
                                   input no,
                                   input no)"""}
      end.   /* qo_fr_terms <> "" */
   end.   /* if qo_fr_terms <> old_fr_terms */

   if rsn_lost <> "" and
      not can-find(first rsn_ref where rsn_code = rsn_lost
                                   and rsn_type = "QUOTE")
   then do:
      /* Invalid Reason Code */
      {pxmsg.i &MSGNUM=655 &ERRORLEVEL=3}
      next-prompt rsn_lost with frame b1.
      undo setb1, retry.
   end.

   for first cm_mstr
      fields(cm_addr cm_promo)
      where cm_addr = qo_cust
   no-lock: end.
/*GUI*/ if global-beam-me-up then undo, leave.


   if available cm_mstr then do:

      for first soc_ctrl
         fields(soc_apm)
      no-lock: end.

      if soc_apm and cm_promo <> ""
      then do:
         hide frame b1 no-pause.
         {gprun.i ""sqqoapm1.p""
            "(input cm_addr,
              input qo_nbr,
              output o-error_flag)"}
/*GUI*/ if global-beam-me-up then undo, leave.

         if o-error_flag then do:
            undo setb1, retry.
         end.
      end.  /* IF SOC_APM AND CM_PROMO <> "" */

   end.  /* IF AVAILABLE CM_MSTR */

   undo_flag = false.

   if qo_fr_terms <> old_fr_terms
   then
      qo_manual_fr_terms = yes.

end. /*setb1*/

hide frame b1 no-pause.
